//============================================================================
// Name        : parameter.h
// Author      : Yugi
// Version     : 1.0
// Description : 
//============================================================================

#ifndef _PARAMETER_H
#define _PARAMETER_H

#include <stdlib.h>
#include <stdio.h>
#include <dr_api.h>

#include "worklist.h"

#define BUF_SIZE 256
#define KEY_SIZE 32
#define VALUE_SIZE 128

/* Structure of property */
typedef struct _PROPERTY{
	char *key;
	char *value;
	struct _PROPERTY *next;
} PROPERTY, *PPROPERTY;

/*
* Get option from string 'options' according to 'optcode'
*
* REQUIRE:	options not NULL
*			optcode can be any inputable character but ' ' followed by -
* RETURN:	option from string 'options' according to 'optcode'
* EXAMPLE:	INPUT	"-aFoo -bBar", 'b'
*			OUTPUT	"Bar"
* NOTES:	Return value should be freed by user
*/
char* pa_option(const char* options, char optcode);

/*
* Parse the file 'input' and save the key-value pair into
* properties.
*
* REQUIRE:	input not NULL
*			<file format>
*				key1 = content1
*				key2 = content2
*				EOF
* EXAMPLE:	INPUT	<file content>
*					key1 = content1
*					key2 = content2
*					EOF
*/
void pa_file(file_t input);

/*
* Get property according to key
*
* REQUIRE:	key not NULL
* RETURN:	value that matches key
*/
char *pa_property(char *key);

/*
* This method compares int-value instead of char*. To match "%esp", 
* we only have to translate it to 'p''s''e''%' (0x70736525).Note
* that it only works right on little endian machines, and for now  
* only %eax, %ecx, %edx, %ebx, %esp, %ebp, %esi, %edi can be 
* recognized.
*
* REQUIRE:	src not NULL
* RETURN:	register id
* EXAMPLE:	INPUT	%esp
*			OUTPUT	REG_ESP
*/
reg_id_t pa_register(char *src);

/*
* Encode operand. Now it support two kinds of operands: registers 
* and base-disp operands. 
*
* REQUIRE:	src not NULL
* RETURN:	operand encoded using 'src'. Empty operand if we cannot
*			parse it.
*/
opnd_t pa_operand(char *src);

/*
* Encode operands using pa_operand() and store them in worklist.
*
* REQUIRE:	src not NULL
* RETURN:	worklist that contains operands encoded from src.
*/
PWORKLIST pa_operands(char *src);

#endif /* End of _PARAMETER_H */
